import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif

import uView from "uview-ui";
Vue.use(uView);

//192.168.9.100
let baseurl = config.url
const request = (url, data = {}, methods = 'post', header = {}) => {
	if (Boolean(url) === false) {
		return;
	}
	//查询本地缓存
	let userinfo = uni.getStorageSync('userInfo') || "";
	let token = userinfo.token || ''
	let query = uni.getStorageSync('scanCode')
	console.log(query)
	let db = query.type || ''
	let that = this;
	// uni.showLoading({
	// 	title: '加载中...',
	// 	mask: true
	// });
	// header['Access-Token'] = userinfo.token || ""
	header['Authorization'] = "Bearer " + token || ""
	header['content-type'] = "application/json;charset:utf-8"
	header['BaseMap'] = db
	return new Promise((resolve, reject) => {
		uni.request({
			method: methods,
			url: baseurl + url,
			data: data,
			header: header,
			dataType: 'json',
		}).then((response) => {
			if(response.data.code == 900){
				uni.reLaunch({
					url:'/pages/login/login'
				})
				return
			}
			uni.hideLoading();
			resolve(response.data);
		}).catch(error => {
			reject(error)
		})
	});
}
Vue.prototype.$http = request;